package domain;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Lob;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.hibernate.annotations.NamedQueries;
import org.hibernate.annotations.NamedQuery;
import org.hibernate.validator.NotNull;
import org.hibernate.validator.Past;
import org.hibernate.validator.constraints.NotEmpty;

/**
 *
 * @author yuyok
 */
@Entity(name = "Video")
@NamedQueries({
    @NamedQuery(name = "getVideoByName",
    query = "SELECT v FROM Video v WHERE v.name = :name")
})
public class Video extends DomainObject {

    private static final long serialVersionUID = 1L;
    @NotEmpty(message = "please, fill in video name")
    private String name;
    @Lob
    private String description;
    @Temporal(TemporalType.DATE)
    @Past
    private Calendar releasedYear;
    @Temporal(TemporalType.DATE)
    private Calendar addedDate;
    @NotEmpty
    private String url;
    @NotNull
    private boolean isEnable = false;
    @OneToMany(mappedBy = "video", cascade = CascadeType.ALL) // TODO: cascade ?? 
    private List<Comment> comments = new ArrayList<Comment>();
    @ManyToMany(mappedBy = "videos", fetch= FetchType.EAGER)
    private List<VideoCategory> videoCategories = new ArrayList<VideoCategory>();
    @ManyToOne
    private User user;

    public Video() {
    }

    public Video(String name, Calendar addedDate, VideoCategory videoCategory) {
        super();
        this.name = name;
        this.addedDate = addedDate;
        this.videoCategories.add(videoCategory);
    }

    public List<Comment> getComments() {
        return this.comments;
    }

    public void addComment(Comment comment) {
        this.comments.add(comment);
    }

    public List<VideoCategory> getVideoCategories() {
        return this.videoCategories;
    }

    public void addVideoCategory(VideoCategory videoCategory) {
        this.videoCategories.add(videoCategory);
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public void setAddedDate(Calendar addedDate) {
        this.addedDate = addedDate;
    }

    public Calendar getAddedDate() {
        return addedDate;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getName() {
        return this.name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Calendar getReleasedYear() {
        return releasedYear;
    }

    public void setReleasedYear(Calendar releasedYear) {
        this.releasedYear = releasedYear;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public boolean isEnable() {
        return isEnable;
    }

    public void setIsEnable(boolean isEnable) {
        this.isEnable = isEnable;
    }
}
